if (process.env.npm_config_argv != undefined) {
  // 解析指令参数
  // npm指令需要读取 process.env.npm_config_argv
  const argv = JSON.parse(process.env.npm_config_argv);
  // vue-cli-service指令需要读取 process.argv，我用的是npm
  // const argv1 = process.argv;
  // console.log("process.env.npm_config_argv值", argv)
  // console.log("process.argv值", argv1)
  const config = {};
  // 获取自定义参数
  let idx = 2;
  const cooked = argv.cooked;
  const length = argv.cooked.length;
  while ((idx += 2) <= length) {
    config[cooked[idx - 2]] = cooked[idx - 1];
  }
  //console.log(config['--platformId'], config['--path']);
  //命令行打包配置自定义参数，入参有值就取自定义值，入参没有值就默认env变量默认值
  if (config['--baseUrl']) {
    process.env.VUE_APP_BASE_URL = config['--baseUrl'];
  }
  if (config['--platformId']) {
    process.env.VUE_APP_PLATFORMID = config['--platformId'];
  }
  if (config['--captchaAppId']) {
    process.env.VUE_APP_SDK_APP_ID = config['--captchaAppId'];
  }
  if (config['--rsaPublicKey']) {
    process.env.VUE_APP_PUBLICKEY = config['--rsaPublicKey'];
  }
  if (config['--path']) {
    process.env.VUE_APP_PATH = config['--path'];
  }

  require('./src/modifyManifest');
}

const TransformPages = require('uni-read-pages');
const { webpack } = new TransformPages();

module.exports = {
  transpileDependencies: ['uni-simple-router', 'uview-ui'],
  configureWebpack: {
    plugins: [
      new webpack.DefinePlugin({
        ROUTES: webpack.DefinePlugin.runtimeValue(() => {
          const tfPages = new TransformPages({
            includes: ['path', 'name', 'aliasPath'],
          });
          return JSON.stringify(tfPages.routes);
        }, true),
      }),
    ],
  },
  devServer: {
    proxy: {
      '/energy-buyer-mapi/buy-mapi': {
        target: process.env.VUE_APP_BASE_URL,
        changeOrigin: false,
      },
      '': {
        target: process.env.VUE_APP_BASE_URL,
        changeOrigin: false,
      },
    },
  },
};
